package pl.edu.mimuw.irs.core.model.design.resource;

import java.io.Serializable;


/**
 * @author Jakub Rauch
 * Created on: 2009-05-07
 */
public class Role implements Serializable, IMember {

	private static final long serialVersionUID = -4357290952775097127L;

	// *** Attributes
	
	private String name;
	private Roles roles;
	// Getters and setters
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Roles getRoles() {
		return roles;
	}
	@SuppressWarnings("unchecked")
	public IHolder getHolder() {
		return getRoles();
	}
	public void setRoles(Roles roles) {
		if (this.roles == roles) return;
		Roles oldParent = null;
		if (this.roles != null) oldParent = this.roles;
		this.roles = roles;
		if (oldParent != null) oldParent.remove(this);
	}
	
	// *** Constructors
	public Role(String name) {
		setName(name);
	}
	
	// *** Methods
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Role &&
				((Role)obj).getName().equals(getName())) {
			return true;
		} else {
			return false;
		}
	}
	
	@Override
	public int hashCode() {
		return getName().hashCode();
	}	

	@Override
	public String toString() {
		return getName();
	}
	
	public void delete() {
		getRoles().remove(this);
	}
	
	@Override
	public Role copy() {
		throw new UnsupportedOperationException();
	}
	
	
}
